const fs = require('fs');
const express = require('express');
//  fs
fs.mkdirSync('./db', {
    recursive: true,
})
fs.writeFileSync('./db/pets.json', '[]');
//  express
const app = express();

app.use(express.urlencoded());
app.use('/', express.static('./public'));

// get
app.get('/api/v1/pets', (req, res) => {
    res.json([{
            id: 1,
            name: '11'
        },
        {
            id: 2,
            name: '22'
        },
        {
            id: 3,
            name: '33'
        },
        {
            id: 4,
            name: '44'
        },
    ]);
});
// post
app.post('/api/v1/pets', (req, res) => {
    res.json({
        code: 1,
        msg: '保存数据成功',
        data: req.body,
    });
});
// 端口号
app.listen(2222, () => {
    console.log('服务器运行在3333端口');
});